#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
    const char *filename = "./test.txt";
    int fd = open(filename,O_RDONLY | O_CREAT,0644);
    if(fd == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd = %d\n",fd);
    /*绝对路径：从根目录开始的绝对路径，如/usr/local/bin/ls，/home/lvguanzhong/code/fundamentals-of-c-language/test268/268systemPramgram/IOPramgram/openDemo.c；相对路径：相对于当前目录的路径，如./test.txt，../test.txt，../../test.txt*/
    const char *filename2 = "dst.txxt";
    int fd2 =  open(filename2,O_WRONLY | O_CREAT,0777);
    if(fd2 == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd2 = %d\n",fd2);
    /*关闭文件fd*/
    close(fd);

    const char *filename3 = "file3.txxt";
    int fd3 =  open(filename3,O_WRONLY | O_CREAT,0777);
    if(fd3 == -1)
    {
        perror("open error:");
        exit(-1);
    }
    printf("fd3 = %d\n",fd3);
    return 0;
}